/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;

import doan.quanlycanbo.portlet.NoSuchhosoException;
import doan.quanlycanbo.portlet.model.hocham;
import doan.quanlycanbo.portlet.model.hocvi;
import doan.quanlycanbo.portlet.model.hoso;
import doan.quanlycanbo.portlet.service.hochamLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hocviLocalServiceUtil;
import doan.quanlycanbo.portlet.service.hosoLocalServiceUtil;
import doan.quanlycanbo.portlet.service.base.hosoLocalServiceBaseImpl;

/**
 * 
 * @author Nguyen Tuan Vinh
 */
public class hosoLocalServiceImpl extends hosoLocalServiceBaseImpl {
	
	public List<hoso> getAll() throws SystemException{
		return hosoPersistence.findAll();
	}
	
	public hoso getByPrimaryKey(long idHoso) throws NoSuchhosoException, SystemException{
		return hosoPersistence.findByPrimaryKey(idHoso);
	}
	
	public List<hoso> getByDonVi(long madonvi) throws SystemException{
		return hosoPersistence.findByDonVi(madonvi);
	}
	
	public List<hoso> getByChucVu(long machucvu) throws SystemException{
		return hosoPersistence.findByChucVu(machucvu);
	}
	
	public List<hoso> getByHocHam(long mahocham) throws SystemException{
		return hosoPersistence.findByHocHam(mahocham);
	}
	
	public List<hoso> getByHocVi(long mahocvi) throws SystemException{
		return hosoPersistence.findByHocVi(mahocvi);
	}
	
	public List<hoso> getByCapUY(long macapuy) throws SystemException{
		return hosoPersistence.findByCapUy(macapuy);
	}
	
	public List<hoso> getByDanhHieu(long madanhhieu) throws SystemException{
		return hosoPersistence.findByDanhHieu(madanhhieu);
	}
	
	public List<hoso> getByDanToc(long madantoc) throws SystemException{
		return hosoPersistence.findByDantoc(madantoc);
	}
	
	public List<hoso> getByTonGiao(long matongiao) throws SystemException{
		return hosoPersistence.findByTonGiao(matongiao);
	}
	
	public List<hoso> getByXuatThan(long maxuatthan) throws SystemException{
		return hosoPersistence.findByXuatthan(maxuatthan);
	}
	
	public List<hoso> getByGDPT(long magdpt) throws SystemException{
		return hosoPersistence.findByGDPT(magdpt);
	}
	
	public List<hoso> getByHeSoLuong(long mahsl) throws SystemException{
		return hosoPersistence.findByHeSoLuong(mahsl);
	}
	
	public String getHH_HV(long maHoso) throws PortalException, SystemException{
		String hh_hv = "";
		hoso hs = hosoLocalServiceUtil.gethoso(maHoso);
		long maHocham = hs.getMahocham();
		long maHocvi = hs.getMahocvi();
		if(maHocham != 0){
			hocham hh = hochamLocalServiceUtil.gethocham(maHocham);
			hh_hv = hh_hv + hh.getTenhocham() + ".";
		}
		if(maHocvi != 0){
			hocvi hv = hocviLocalServiceUtil.gethocvi(maHocvi);
			hh_hv = hh_hv + hv.getTenhocvi() + ".";
		}
		
		return hh_hv;
	}
	
	public hoso addHoso(long groupId, long companyId, String languageId, long userId, long sohieunv, String cmtnd,
			String hoten, String gioitinh, String tenthuongdung, Date ngaysinh, String noisinh, String quequan,
			String diachithuongtru, String diachitamtru, String dienthoai, String email, String quocgia,
			Date ngayVaoDang, String cntn1, int namtn1, String cntn2, int namtn2, String cntn3, int namtn3,
			long madonvi, long machucvu, long madantoc, long mahocham, long mahocvi, long mahesoluong,
			long macapuy, long matongiao, long maxuatthan, long magdpt, long madanhhieu, int vitri) throws SystemException{
		
		long maHoso = CounterLocalServiceUtil.increment(hoso.class.getName());
		hoso hoso2 = hosoPersistence.create(maHoso);
		
		hoso2.setGroupId(groupId);
		hoso2.setCompanyId(companyId);
		hoso2.setLanguageId(languageId);
		
		hoso2.setSohieunhanvien(sohieunv);
		hoso2.setCmtnd(cmtnd);
		hoso2.setHoten(hoten);
		hoso2.setGioitinh(gioitinh);
		hoso2.setTenthuongdung(tenthuongdung);
		hoso2.setNgaysinh(ngaysinh);
		hoso2.setNoisinh(noisinh);
		hoso2.setQuequan(quequan);
		hoso2.setDiachithuongtru(diachithuongtru);
		hoso2.setDiachitamtru(diachitamtru);
		hoso2.setDienthoai(dienthoai);
		hoso2.setEmail(email);
		hoso2.setQuocgia(quocgia);
		
		hoso2.setNgayvaodang(ngayVaoDang);
		hoso2.setChuyennganh1(cntn1);
		hoso2.setNamtncn1(namtn1);
		hoso2.setChuyennganh2(cntn2);
		hoso2.setNamtncn2(namtn2);
		hoso2.setChuyennganh3(cntn3);
		hoso2.setNamtncn3(namtn3);
		
		hoso2.setMadonvi(madonvi);
		hoso2.setMachucvu(machucvu);
		hoso2.setMadantoc(madantoc);
		hoso2.setMahocham(mahocham);
		hoso2.setMahocvi(mahocvi);
		
		hoso2.setMahesoluong(mahesoluong);
		hoso2.setMacapuy(macapuy);
		hoso2.setMatongiao(matongiao);
		hoso2.setMaxuatthan(maxuatthan);
		hoso2.setMagdpt(magdpt);
		hoso2.setMadanhhieu(madanhhieu);
		hoso2.setVitri(vitri);
		
//		try {
//			resourceLocalService.addResources(companyId, groupId, userId, 
//					hoso.class.getName(), hoso2.getPrimaryKey(), false, true, true);
//		} catch (PortalException e) {
//			e.printStackTrace();
//		}
		
		return hosoPersistence.update(hoso2, false);
	}
	
	public hoso updateHoso(long maHoso, long sohieunv, String cmtnd, String hoten, String gioitinh, String tenthuongdung, 
			Date ngaysinh, String noisinh, String quequan, String diachithuongtru, String diachitamtru,String dienthoai, 
			String email, String quocgia, Date ngayvaodang, String cntn1, int namtncn1, String cntn2, int namtncn2,String cntn3, 
			int namtncn3, long madonvi, long machucvu, long madantoc, long mahocham, long mahocvi, long mahesoluong,
			long macapuy, long matongiao, long maxuatthan, long magdpt, long madanhhieu, int vitri) throws NoSuchhosoException, SystemException{
		
		hoso hosoUpdate = hosoPersistence.findByPrimaryKey(maHoso);
		hosoUpdate.setSohieunhanvien(sohieunv);
		hosoUpdate.setCmtnd(cmtnd);
		hosoUpdate.setHoten(hoten);
		hosoUpdate.setGioitinh(gioitinh);
		hosoUpdate.setTenthuongdung(tenthuongdung);
		
		hosoUpdate.setNgaysinh(ngaysinh);
		hosoUpdate.setNoisinh(noisinh);
		hosoUpdate.setQuequan(quequan);
		hosoUpdate.setDiachithuongtru(diachithuongtru);
		hosoUpdate.setDiachitamtru(diachitamtru);
		hosoUpdate.setDienthoai(dienthoai);
		hosoUpdate.setEmail(email);
		hosoUpdate.setQuocgia(quocgia);
		
		hosoUpdate.setNgayvaodang(ngayvaodang);
		hosoUpdate.setChuyennganh1(cntn1);
		hosoUpdate.setNamtncn1(namtncn1);
		hosoUpdate.setChuyennganh1(cntn2);
		hosoUpdate.setNamtncn1(namtncn2);
		hosoUpdate.setChuyennganh1(cntn2);
		hosoUpdate.setNamtncn1(namtncn2);
		
		hosoUpdate.setMadonvi(madonvi);
		hosoUpdate.setMachucvu(machucvu);
		hosoUpdate.setMadantoc(madantoc);
		hosoUpdate.setMahocham(mahocham);
		hosoUpdate.setMahocvi(mahocvi);
		hosoUpdate.setMahesoluong(mahesoluong);
		hosoUpdate.setMacapuy(macapuy);
		hosoUpdate.setMatongiao(matongiao);
		hosoUpdate.setMaxuatthan(maxuatthan);
		hosoUpdate.setMagdpt(magdpt);
		hosoUpdate.setMadanhhieu(madanhhieu);
		hosoUpdate.setVitri(vitri);
		
		return hosoUpdate;
	}
	
	public void deleteHoso(long maHoso) throws SystemException, PortalException{
		hoso hosoDel = hosoPersistence.findByPrimaryKey(maHoso);
		deleteHoso(hosoDel);
	}
	
	public void deleteHoso(hoso hosoDel) throws PortalException, SystemException{
		resourceLocalService.deleteResource(hosoDel.getCompanyId(), hoso.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, hosoDel.getPrimaryKey());
		hosoPersistence.remove(hosoDel);
	}
}














